﻿//
// Created by Administrator on 2022/1/29.
//

#include "AddDirectoryDialog.h"

BEGIN_EVENT_TABLE ( AddDirectoryDialog, wxDialog )
                EVT_BUTTON ( ID_OK, AddDirectoryDialog::OnOk )
                EVT_BUTTON ( ID_CANCEL, AddDirectoryDialog::OnCancel )
END_EVENT_TABLE()

//通过消息传达添加监控目录的需求
/*
 * FILE_NOTIFY_CHANGE_LAST_WRITE
        | FILE_NOTIFY_CHANGE_CREATION
        | FILE_NOTIFY_CHANGE_FILE_NAME
        | FILE_NOTIFY_CHANGE_DIR_NAME;
 */
AddDirectoryDialog::AddDirectoryDialog( wxWindow *parent, wxString path )
    :wxDialog( parent, wxID_ANY, "确认配置" ) {
    ok = false;
    this->path  = path;
    SetClientSize ( wxSize ( 350, 300 ) );
    dialogRootBoxSizer = new wxBoxSizer ( wxVERTICAL );
    auto *text = new wxTextCtrl( this, wxID_ANY, path );
    dialogRootBoxSizer->Add( text, 0,wxALL | wxEXPAND, 5 );
    cb_last_write = new wxCheckBox( this, ID_LAST_WRITE, wxT("FILE_NOTIFY_CHANGE_LAST_WRITE"),
                                  wxDefaultPosition, wxDefaultSize, 0 );
    cb_create = new wxCheckBox( this, ID_CHANGE_CREATION, wxT("FILE_NOTIFY_CHANGE_CREATION"),
                                  wxDefaultPosition, wxDefaultSize, 0 );
    cb_file_name = new wxCheckBox( this, ID_CHANGE_FILE_NAME, wxT("FILE_NOTIFY_CHANGE_FILE_NAME"),
            wxDefaultPosition, wxDefaultSize, 0 );
    cb_dir_name = new wxCheckBox( this, ID_CHANGE_DIR_NAME, wxT("FILE_NOTIFY_CHANGE_DIR_NAME"),
            wxDefaultPosition, wxDefaultSize, 0 );
    cb_subtree= new wxCheckBox( this, ID_CHANGE_DIR_NAME, wxT("FILE_NOTIFY_CHANGE_DIR_NAME"),
                                wxDefaultPosition, wxDefaultSize, 0 );
    cb_last_write->SetValue( true );
    cb_create->SetValue( true );
    cb_file_name->SetValue( true );
    cb_dir_name->SetValue( true );
    cb_subtree->SetValue( true );
    dialogRootBoxSizer->Add ( cb_last_write, 0, wxALL | wxEXPAND, 5 );
    dialogRootBoxSizer->Add ( cb_create, 0, wxALL | wxEXPAND, 5 );
    dialogRootBoxSizer->Add ( cb_file_name, 0, wxALL | wxEXPAND, 5 );
    dialogRootBoxSizer->Add ( cb_dir_name, 0, wxALL | wxEXPAND, 5 );
    dialogRootBoxSizer->Add ( cb_subtree, 0, wxALL | wxEXPAND, 5 );
    auto *boxSize = new wxBoxSizer ( wxHORIZONTAL );

    bt_ok = new wxButton( this, ID_OK, wxT("确认") );
    bt_cancel = new wxButton( this, ID_CANCEL, wxT("取消" ) );
    boxSize->Add( bt_ok );
    boxSize->Add( bt_cancel );

    dialogRootBoxSizer->Add ( boxSize, 0, wxALL | wxEXPAND, 5 );
    SetSizer( dialogRootBoxSizer );
    //title
    //add, cancel

}

AddDirectoryDialog::~AddDirectoryDialog() {

}

void AddDirectoryDialog::OnOk(wxCommandEvent &event) {
    ok  = true;
    this->Hide();
}

DWORD AddDirectoryDialog::getNotificationFlags() {
    //DWORD flags = 0;
    return cb_last_write->GetValue() |cb_create->GetValue()
        | cb_file_name->GetValue() | cb_dir_name->GetValue() ;
}

void AddDirectoryDialog::OnCancel(wxCommandEvent &event) {
    this->Hide();
}

bool AddDirectoryDialog::getSubTree() {
    return cb_subtree->GetValue();
}

MonitorDIR AddDirectoryDialog::getMonitorDir() {
    MonitorDIR monitorDir;
    monitorDir.path = path;
    monitorDir.create = cb_create->GetValue();
    monitorDir.last_write = cb_last_write->GetValue();
    monitorDir.dir_name = cb_dir_name->GetValue();
    monitorDir.subTree = cb_subtree->GetValue();
    monitorDir.file_name = cb_file_name->GetValue();
    return monitorDir;
}
